package com.coc.action;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.zip.*;

import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Test extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public Test() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	//	ServletInputStream sis = request.getInputStream();
		InputStream is = request.getInputStream(); 
		InflaterInputStream sis = new InflaterInputStream(is);
		DataInputStream input = new DataInputStream(new InflaterInputStream(is));
	//	System.out.println("str="+input.readBoolean());
		System.out.println("str="+input.readUTF());
		
        
		ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
		byte[] buff = new byte[100]; 
		int rc = 0;
		while ((rc = sis.read(buff, 0, 100)) > 0) {
			swapStream.write(buff, 0, rc);
		}
//		byte[] in_b = swapStream.toByteArray(); 
//		byte gzip = in_b[0];
//		byte[] data = new byte[in_b.length-1];
//		for(int i=1;i<in_b.length;i++){
//			data[i-1]=in_b[i];
//		}
//		String str = new String(data,"UTF-8");
//		System.out.println("str="+str);
		
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
